﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Models;
using BLL;

namespace Player.Admin
{
    public partial class comments : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                rpt_commentsSX();
                //修改信息框展示
                if (Request.QueryString["upid"] != null)
                {
                    this.pl_add.Visible = false;
                    this.Pl_update.Visible = true;
                    //赋值
                    int id = Convert.ToInt32(Request.QueryString["upid"]);
                    this.lbl_pl2cmid.Text = id.ToString();
                    List<Comments> ls = BLL.CommentsManage.SeleIdComments(id);
                    this.txt_pl2usid.Text = ls[0].Cm_UsId.ToString();
                    this.txt_pl2gmid.Text = ls[0].Cm_GmId.ToString();
                    this.txt_pl2gmname.Text = ls[0].Cm_Title.ToString();
                    this.txt_pl2img.Text = ls[0].Cm_Image.ToString();
                    this.txt_pl2desc.Text = ls[0].Cm_Desc.ToString();
                    this.txt_pl2date.Text = ls[0].Cm_Date.ToShortDateString();
                }
                //删除提示
                if (Request.QueryString["deid"] != null)
                {
                    this.pl_delete.Visible = true;
                }
            }

            

        }

        //刷新表
        private void rpt_commentsSX()
        {
            this.rpt.DataSource = BLL.CommentsManage.SeleAllComments();
            this.rpt.DataBind();
        }

        //添加信息框显示
        protected void btn_add_Click(object sender, EventArgs e)
        {
            this.Pl_update.Visible = false;
            this.pl_add.Visible = true;
            this.lbl_pltitle.Text = "添加信息";
        }

        //添加信息框隐藏
        protected void btn_plgb_Click(object sender, EventArgs e)
        {
            this.pl_add.Visible = false;
        }

        //保存添加信息
        protected void txt_plctrls_Click(object sender, EventArgs e)
        {
            //获取输入内容保存至Comments中
            Comments cm = new Comments();
            cm.Cm_UsId = Convert.ToInt32(this.txt_plusid.Text.Trim());
            cm.Cm_GmId = Convert.ToInt32(this.txt_plgmid.Text.Trim());
            cm.Cm_Title = this.txt_plgamemame.Text.Trim();
            cm.Cm_Image = this.txt_plimg.Text.Trim();
            cm.Cm_Desc = this.txt_pldesc.Text.Trim();
            cm.Cm_Date = Convert.ToDateTime(this.txt_pldate.Text.Trim());
            //保存操作
            bool bl = BLL.CommentsManage.AddimgComments(cm);
            if (bl)
            {
                this.lbl_pl1bcts.Text = "保存成功";
                //刷新表
                rpt_commentsSX();
            }
            else
            {
                this.lbl_pl1bcts.Text = "保存失败";
            }
        }

        //保存修改信息
        protected void btn_pl2bc_Click(object sender, EventArgs e)
        {
            //获取内容保存至Comments中
            Comments cm = new Comments();
            cm.Cm_Id = Convert.ToInt32(this.lbl_pl2cmid.Text.Trim());
            cm.Cm_UsId = Convert.ToInt32(this.txt_pl2usid.Text.Trim());
            cm.Cm_GmId = Convert.ToInt32(this.txt_pl2gmid.Text.Trim());
            cm.Cm_Title = this.txt_pl2gmname.Text.Trim();
            cm.Cm_Image = this.txt_pl2img.Text.Trim();
            cm.Cm_Desc = this.txt_pl2desc.Text.Trim();
            cm.Cm_Date = Convert.ToDateTime(this.txt_pl2date.Text.Trim());
            //执行修改
            bool bl = BLL.CommentsManage.UpdaComments(cm);
            if (bl)
            {
                this.lbl_pl2bcts.Text = "保存成功";
                //刷新表
                rpt_commentsSX();
            }
            else
            {
                this.lbl_pl2bcts.Text = "保存失败";
            }
        }
        
        //修改信息框隐藏
        protected void btn_pl2gb_Click(object sender, EventArgs e)
        {
            this.Pl_update.Visible = false;
        }

        //用户名替换用户Id
        public string UsIdisName(string id)
        {
            List<Users> ls = BLL.UsersManage.SeleIdUsers(Convert.ToInt32(id));
            return ls[0].Us_Name.ToString();
        }

        //确定删除
        protected void btn_delequedin_Click(object sender, EventArgs e)
        {
            int id = Convert.ToInt32(Request.QueryString["deid"]);
            bool bl = BLL.CommentsManage.DeleComments(id);
            if (bl)
            {
                this.pl_delete.Visible = false;
                //刷新表信息
                rpt_commentsSX();
            }
        }

        //取消删除
        protected void btn_delequxiao_Click(object sender, EventArgs e)
        {
            this.pl_delete.Visible = false;
        }

        //查询
        protected void imgbtn_Click(object sender, ImageClickEventArgs e)
        {
            //获取输入内容
            string gmname = this.txt_usid.Text.Trim();
            //输入是否为空
            if (gmname == "")
            {
                this.lbl_ChaXunTiShi.Text = "请输入查询内容";
                this.img_weizhaodao.Visible = true;
                return;
            }
            //执行查询操作
            List<Comments> ls = BLL.CommentsManage.SeleLikeGameNameComments(gmname);
            //查询结果是否为空
            if (ls.Count==0)
            {
                this.lbl_ChaXunTiShi.Text = "未找到相关内容";
                this.img_weizhaodao.Visible = true;
                return;
            }
            this.lbl_ChaXunTiShi.Text = "";
            this.img_weizhaodao.Visible = false;
            this.rpt.DataSource = ls;
            this.rpt.DataBind();
            
        }
        //刷新
        protected void imgbtnsx_Click(object sender, ImageClickEventArgs e)
        {
            rpt_commentsSX();
        }

        protected void imgbtnsx_Click1(object sender, ImageClickEventArgs e)
        {

        }
        
    }
}